Last saved by: pre-installed user

USING EEPROMS
A COMMENTARY FROM MCM DESIGN
Revision 1.0

I am very partial to EEPROMs as opposed to EPROMs. No UV eraser is required and you can easily change any byte as desired. With the newer redesigned EEPROMs, you can turn on, within the EEPROM, an optional software data protection feature using a simple specific write byte sequence, so the EEPROM acts like an EPROM. When this feature is turned on, you cannot change the EEPROM data until you write another specific write byte sequence to turn this protection feature off. This is a very effective option. Note that an EEPROM with this data protection feature may be shipped to you with the feature turned on. You will then have to turn off this feature, so you can program the EEPROM. I have received Xicor EEPROMs from Jameco Electronics with the data protection turned on. The first time I attempted to program one of these EEPROMs, I thought the chip was bad because I couldn't change any bytes in the EEPROM. I checked the data sheet and found out about its optional data protection feature. Then I learned how to turn the protection off.

By the way, the data retention in EEPROMs, which I programmed way back in the 1980s, is excellent. I was amazed that the data in these EEPROMs after 35 years was 100% intact.

I have been programming 32Kx8 bit EEPROMs purchased at Jameco Electronics, part #74878, currently selling at $4.95 each and 10 at $4.49. There is currently a little over 100 in stock. Whether or not they will discontinue this item once the stock is depleted remains to be seen. They apparently bought a batch of EEPROMs by Xicor. These chips look brand-new and are shipped with the pins spread outward in the "factory fresh" position, suggesting they are brand-new.

I have been using my EEPROMs lately for various projects to test newly created hardware, but eventually plan to begin creating cartridge form programs that run in the hi-res mode.

My hi-res Astrocade has a 28 pin user static RAM socket addressed 6000-7FFFH and a 28 pin user static RAM socket addressed 8000-FFFFH. There is a write protect switch to help protect a chip in one of these sockets from inadvertent writes. The Jameco EEPROM is pin compatible with both of these sockets. So, I can just insert an EEPROM into one of these sockets and begin programming the EEPROM using Bit Fiddler's MLM or my hi-res MLM. Byte changes/corrections can be made quite easily when I am creating a brand-new program to run at 2000H, 6000H or 8000H. My 6000H socket is multi-carted for a 32KB EEPROM, using a dual position DIP switch, to run one of four 8KB programs. When switched to 2000H, via a mini toggle switch, 2000H programs in this socket can be executed. This feature is great for developing cartridge form programs.

My user RAM set up allows ML program copying into an EEPROM. I can copy Astrobasic programs saved on tape and also Astrobasic Wav files. What I do is insert a pin compatible static RAM chip in the 6000H socket and an EEPROM in the 8000H socket. The program on tape is loaded into the static RAM at 6000H using the Astrobasic audio tape interface. Then, I use a simple short machine language program using Bit Fiddler's MLM to copy the program into the EEPROM at 8000H. The hand written copy and check ML routines I use are posted on the Bally Alley website.

https://ballyalley.com/ml/ml_homebrew/EEPROM_Programmer/EEPROM%20Programmer%20(2017)(Michael%20Matte).pdf

Unfortunately, it takes 137 seconds to copy an 8KB program to the EEPROM using the ML copy routine mentioned above. Someday I will take another look at that copy routine to see if I can speed up the copy time. MLM's screen interrupts are probably slowing down the copy routine. I might be able to speed up the copy routine by simply adding two Z80 instructions to the copy routine to disable the interrupts (DI) prior to executing the copy routine and then end the copy routine enabling the interrupts (EI) again. I recently discovered that the newer redesigned EEPROMs have an optional "Page Write Operation" allowing faster writes into an EEPROM. I believe I have enough info on this optional feature to create a ML copy routine that will copy 8KB of data into this kind of EEPROM in just a few seconds.

I found out you can download an Astrobasic Wav file from your desk or laptop directly into an audio cassette recorder. I took a stereo audio cable with 3.5mm plugs on each end and spliced a 100K ohm resistor into the appropriate stereo channel wire. I also cut the unused stereo channel wire so it would not connect to anything. So, one end of the audio cable gets plugged into a 3.5mm audio output (line out) jack on my desktop and the other end into the 3.5mm microphone input jack on my cassette recorder. This setup works very well without having to adjust the desktop's audio output level. You simply play the Wav file and record directly onto cassette tape.

An EEPROM acts very similar to a static RAM chip. However, during a normal write attempt, there is a time delay before the chip will accept another byte of data written to it. The required waiting time before another byte can be written can be as high as 10ms. For this reason, you cannot load an Astrobasic program on tape directly into an EEPROM inserted into a user RAM socket. You have to load the program into a user static RAM chip (or set of DRAM chips) and then use a ML/AL routine with a time delay between normal write byte attempts to copy the program from user RAM into an EEPROM. This time delay parameter is labeled as "write cycle time" (Twc) and may be listed in the manufacturer's data sheet within a write cycle parameter table. This parameter Twc may typically be 5ms. You can also experimentally determine this parameter by tweaking the time delay within the ML/AL copy routine. The time delay however, may vary with each EEPROM. With my recent discovery mentioned above, the newer EEPROMs can be copied very fast using the optional page write feature.

Once you finish programming an EEPROM and you are ready to install it for your particular application, if it has a software data protection feature, you should turn on that option. See the examples below to learn how to implement this feature. Another recommendation is to ground the EEPROM's active low output enable (OE) pin, which should inhibit any inadvertent write cycle. Refer to the manufacturer's data sheet for more info on inhibiting any inadvertent write cycle.

On my hi-res Astrocade, I use a DPDT mini toggle switch for the 28 pin 6000/2000H user RAM socket. One pole is wired to the active low chip enable (CE) pin for the 6000H or 2000H address selection. The other pole is wired to the chip's active low output enable (OE) pin. When selecting the 6000H operation, the active low Z80 read (RD) line is fed to the EEPROM's OE pin. When selecting the 2000H operation, the OE pin is grounded.

Using a write protect mini toggle switch wired to a user RAM socket is a good way to help protect program data. You can write data into the RAM or EEPROM, depending on what chip is in the socket. When finished, flip the write protect switch on, then list and check the data bytes written or execute a program. As long as that active low WE pin is at a logic high, it's suppose to protect the program data during a power on or off, inadvertent writes and hopefully during a system crash.

Newer redesigned EEPROM manufacturers like Xicor include an optional "software data protection" feature. Check the specific manufacturer's data sheet for the EEPROM you are using, to see if that EEPROM offers this optional feature. If it does, the data sheet will detail how to turn this feature on or off. All you do is write specific data bytes in a sequence to specific addresses within the EEPROM. There is a specific write byte sequence to turn on (activate) the protect feature and another specific write byte sequence to turn off (deactivate) the protect feature so you can alter or re-program data bytes within the EEPROM. The write byte sequences are probably standardized for various manufacturers. Check the specific manufacturer's data sheet for the EEPROM you are using. Note that the specific address you are suppose to write to may vary depending on the size of the EEPROM you are using. For example, an 8KB EEPROM as opposed to a 32KB EEPROM. Note also that the "write to" addresses shown on the data sheet are the address locations WITHIN the EEPROM, NOT the decoded Z80 memory addresses for the EEPROM socket on your computer. So, the data sheet "write to" addresses in each of the two write sequences will likely be a little confusing when you read the sequence specifics for the first time. When I first attempted utilizing this feature, it took a while to interpret the data sheet specifics for this feature. Use the working examples below to help you interpret the manufacturer's specific write byte to EEPROM addresses, for each of the protect on and protect off write sequences.

Below is a listing of some EEPROM manufacturers, EEPROM designations and whether the EEPROM includes a user selectable data protection feature.

  MFGR	      8KB		32KB		Selectable
		   (8Kx8 bit)  (32Kx8 bit)	Data Protection
							Option

AMD		     Am9864				No
Advanced
Micro Devices

Samsung	     KM2864A			No
Semiconductor    KM2865A
		     KM2864AH
		     KM2865AH
		     H=High 
                performance

Xicor		     X28C64	     X28C256	Yes

Atmel				     AT28C256	Yes

CSI		     		     CAT28C256    Yes
Catalyst
Semiconductor
Inc

SEEQ				     DQ28C256	No
Technology
Inc

EXAMPLE 1

Using the 8Kx8 bit Xicor EEPROM, type X28C64, write a machine language routine to turn on (activate) its optional software data protection feature. Look at the Xicor data sheet for their type X28C64 EEPROM. The write sequence to turn on the data protection is listed below. Note the data bytes and addresses are hexadecimals.

Write data AA to address 1555*
Write data 55 to address 0AAA*
Write data A0 to address 1555*

* This address is the 8KB EEPROM's address location from 0000 to 1FFFH, NOT the computer's Z80 decoded memory address. See the example program below to help you to distinguish this difference.

Note that you only need to write 3 bytes to the EEPROM to activate the data write protection. The EEPROM has also an optional byte/page load of up to 64 bytes. See EXAMPLE 6 below for info on implementing this option. The data for the 3 bytes in this sequence does not actually get written into the specified EEPROM address locations because these write attempts do not meet the EEPROM timing requirements. But, the EEPROM does acknowledge the activate data protection request. The last byte written in the sequence will turn on the data protection feature after the write cycle time Twc has completed.

Note that the 3 bytes in the write sequence are written to the EEPROM's address locations 0AAA and 1555H. If the 8KB EEPROM is going to be placed, to turn on the data protect feature, in a pin compatible user RAM socket that is decoded to operate at the Z80 memory address range 6000-7FFFH, what two addresses should you use in the EEPROM write sequence to turn on the data protection feature?

EEPROM		Binary Equivalent
Address
Location

0AAA			000 0 1010 1010 1010
1555			000 1 0101 0101 0101

With the Z80 16 bit memory addresses, the 3 left most bits are labeled as A15, A14 and A13 respectively and the right most bit is labeled as A0. Bits A15, A14 and A13 in the Z80 memory address range 6000-7FFFH are always set to 011 respectively. So, the 2 addresses that should be written to in the write sequence are shown below. They are 6AAA and 7555H.

Z80			Binary Equipment
Memory
Address

6AAA			011 0 1010 1010 1010
7555			011 1 0101 0101 0101

Let's assume you have an 8KB EEPROM that's been programmed and the EEPROM will be placed in a 28 pin compatible user RAM socket addressed 6000-7FFFH to turn on the data protection feature.

As indicated above, the 2 addresses you should use to turn on the data protect feature in the write sequence are 6AAA and 7555H. Place the EEPROM in the 6000-7FFFH user RAM socket and execute the EXAMPLE 1 PROGRAM below.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EXAMPLE 1 PROGRAM

Activate the data write protection.

This routine turns on the data protection for an 8Kx8 bit Xicor EEPROM, type X28C64 placed in a 28 pin compatible user static RAM socket decoded to operate in the Z80 memory address range 6000-7FFFH.

Use Bit Fiddler's Machine Language Monitor (MLM) to enter and execute the routine below at 4E10H, to turn on the EEPROM's data protection feature.

4E10H	F3		DI			disable screen interrupts
	11 55 75	LD DE,7555H		write byte AA to 7555H 
	3E AA		LD A,AAH
	12		LD (DE),A
	3E 55		LD A,55H		write byte 55 to 6AAAH
4E19H	32 AA 6A	LD (6AAAH),A
	3E A0		LD A,A0H		write byte A0 to 7555H
	12		LD (DE),A
	FB		EI			turn screen interrupts back on
4E20H C9		RET

Write some bytes to the EEPROM to confirm the data protection feature is turned on (activated).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EXAMPLE 2

Using the same EEPROM and user static RAM socket set up as in EXAMPLE 1, how do you turn off the data protection feature?

Use the Xicor data sheet detailing the write sequence to reset (deactivate) the data protection feature. Use also EXAMPLE 1 above as a guide.

Execute the write sequence routine below to turn off the data protection feature.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EXAMPLE 2 PROGRAM

Deactivate the data write protection.

This routine turns off the data protection for an 8Kx8 bit Xicor EEPROM, type X28C64 placed in a 28 pin compatible user static RAM socket decoded to operate in the Z80 memory address range 6000-7FFFH.

Use EXAMPLE 1 above as a guide for the ML routine listed below.

4E10H	F3		DI
	06 55 	LD B,55H
	21 AA 6A	LD HL,6AAAH
	11 55 75	LD DE,7555H
	3E AA		LD A,AAH		write AA to 7555H
	12		LD (DE),A
	70		LD (HL),B		write 55 to 6AAAH
	3E 80		LD A,80H		write 80 to 7555H
	12		LD (DE),A
4E20H	3E AA		LD A,AAH		write AA to 7555H
	12		LD (DE),A
	70		LD (HL),B		write 55 to 6AAAH
	3E 20 	LD A,20H		write 20 to 7555H
	12		LD (DE),A
	FB		EI
4E28H	C9		RET

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EXAMPLE 3

Using EXAMPLE 1 as a guide, write a program that will turn on the data protection feature for a 32Kx8 bit, Xicor EEPROM, type X28C256.

This EEPROM will be placed in a 28 pin compatible user static RAM socket addressed 8000-FFFFH allowing its data protection feature to be turned on.

Looking at the Xicor, type X28C256 data sheet, the write sequence to turn on the data protection is listed below.

Write data AA to address 5555H.
Write data 55 to address 2AAAH.
Write data A0 to address 5555H.

EEPROM		Binary Equivalent
Address
Location

2AAA	 		0 010 1010 1010 1010
5555			0 101 0101 0101 0101

The left most bit is A15 and is always set to logic 1 in the Z80 memory address range 8000-FFFFH. The 2 addresses that should be written to in the write sequence are shown below. They are AAAA and D555H.

Z80			Binary Equivalent
Memory
Address

AAAA			1 010 1010 1010 1010
D555			1 101 0101 0101 0101 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EXAMPLE 3 PROGRAM

Activate the data write protection.

This routine turns on the data protection for an 32Kx8 bit Xicor EEPROM, type X28C256 placed in a 28 pin compatible user static RAM socket decoded to operate in the Z80 memory address range 8000-FFFFH.

This routine also works for Atmel AT28C256 and CSI CAT28C256 EEPROMs. 

Use EXAMPLE 1 above as a guide for the ML routine listed below.
 
Execute the write sequence routine below to turn on the data protection feature.

4E10H	F3		DI			disable screen interrupts
	11 55 D5	LD DE,D555H		write AA to D555H
	3E AA		LD A,AAH
	12		LD (DE),A
	3E 55		LD A,55H		write 55 to AAAAH
4E19H	32 AA AA	LD (AAAAH),A
	3E A0		LD A,AOH		write A0 to D555H
	12		LD (DE),A
	FB		EI			turn screen interrupts back on
4E20H C9		RET

Write some bytes to the EEPROM to confirm the data protection feature is turned on.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EXAMPLE 4

Using the same EEPROM and user static RAM socket set up as in EXAMPLE 3, how do you turn off the data protection feature?

Use the Xicor data sheet detailing the write sequence to reset (deactivate) the data protection feature. Use also EXAMPLE 1 as a guide.
 
Execute the write sequence routine below to turn off the data protection feature.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EXAMPLE 4 PROGRAM

Deactivate the data write protection.

This routine turns off the data protection for an 32Kx8 bit Xicor EEPROM, type X28C256 placed in a 28 pin compatible user static RAM socket decoded to operate in the Z80 memory address range 8000-FFFFH.

This routine also works for Atmel AT28C256 and CSI CAT28C256 EEPROMs. 

Use EXAMPLE 1 above as a guide for the ML routine listed below.

4E10H	F3		DI
	06 55		LD B,55H
	21 AA AA	LD HL,AAAAH
	11 55 D5	LD DE,D555H
	3E AA		LD A,AAH		write AA to D555H
	12		LD (DE),A
	70		LD (HL),B		write 55 to AAAAH
	3E 80		LD A,80H		write 80 to D555H
	12		LD (DE),A
4E20H	3E AA		LD A,AAH		write AA to D555H
	12 		LD (DE),A
	70		LD (HL),B		write 55 to AAAAH
	3E 20 	LD A,20H		write 20 to D555H
	12		LD (DE),A
	FB		EI
4E28H	C9		RET

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EXAMPLE 5

Can you turn on the data protection feature for a 32Kx8 bit Xicor EEPROM, type X28C256 if the EEPROM is placed in a 28 pin compatible user static RAM socket addressed 6000-7FFFH with the EEPROM's address pins A14 and A13 grounded?

Xicor's data sheet indicates that 2 EEPROM addressed locations 2AAA and 5555H must be written to in the write sequence to activate the software data protection feature.

When the EEPROM is placed in the user RAM socket decoded to begin operating at 6000H, the 2 specified EEPROM addresses 2AAA and 5555H become 8AAAH and B555H respectively. These 2 addresses are higher than 7FFFH, so you cannot turn the data protection feature on in this situation.

What about if this user RAM socket was multi-carted for four 8KB banks? Could you then turn on the protection feature?

The four 8KB breakdown for a 32KB EEPROM would be as listed below.

Bank		EEPROM
Number	Address Location
		Range

  0		0000-1FFFH

  1		2000-3FFFH

  2		4000-5FFFH

  3		6000-7FFFH

The 2 specified EEPROM addresses to activate the protection write sequence are 2AAA and 5555H, which are located in Bank 1 and Bank 2 respectively. If the user RAM socket is multi-carted for four 8KB banks, you still could NOT turn on the data protection feature by selecting ONE of the 4 banks, because 2AAAH is in Bank 1 and 5555H is in Bank 2. The EEPROM must be placed in a socket that will decode BOTH of the EEPROM address locations 2AAA and 5555H if you want to activate or deactivate the EEPROM's data protection feature.

EXAMPLE 6
Activate The Write Protection After Writing To An EEPROM Page Window.
A Trivial Example

Up to 64 bytes can be optionally written to an EEPROM page window immediately following the 3 byte activate write protection sequence. The drawback to this option is that you have to determine "which" bytes that you want to write (or change) are in "which" EEPROM page. The EEPROM has multiple pages. You can only write to a single page at a time using this optional feature. So, it might be easier to just deactivate the write protection, write the appropriate bytes yourself manually and then activate the write protection again.

Let's assume you programmed an 8Kx8 bit Xicor EEPROM, type X28C64. The program runs great at 2000H but you want to change 2 colors in a 4 byte color table which is located at 2003H. You did activate the data protection feature on this EEPROM.

Rather than deactivate the data protection feature, change the color bytes at 2003 and 2004H manually, then reactivate the data protection feature again, there is an easier way to change the 2 colors.

The easiest way, in this case, to change the 2 colors in the EEPROM is to execute a data protection write sequence followed by a byte/page option. This option allows up to 64 bytes within a single page to be written into the EEPROM. After the last byte in this option is written, the data write protection will be turned on. See the Xicor data sheet for more details.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EXAMPLE PROGRAM 6

Activate the data write protection after writing 2 bytes to a page window.

This routine writes 2 bytes to an 8Kx8 bit Xicor EEPROM, type X28C64 in the EEPROM's address locations 0003 and 0004H, then activates the data write protection.

The EEPROM will be placed in a 28 pin compatible user static RAM socket decoded to operate in the Z80 memory address range 6000-7FFFH.

Note 1
The Z80 memory address breakdown for the range 6000-7FFFH is indicated below.
A5-A0 can point up to 64 addressable bytes per page (0-63).
A12-A6 can point up to 128 addressable pages (0-127).
A15-A13 is set to 011 respectively (6000H is the starting address).

Note 2
Page 0 at the 6000H socket is in the range 6000-603FH.
The 2 EEPROM address locations 0003 and 0004H are within the EEPROM's page 0.
These 2 locations 0003 and 0004H will be decoded as 6003 and 6004H respectively.

SEE EXAMPLE 1 AS A GUIDE FOR THE FIRST 3 BYTES WRITTEN TO THE EEPROM
ACTIVATE THE DATA WRITE PROTECTION
4E10H	F3		DI
	11 55 75	LD DE,7555H		write byte AA to 7555H
	3E AA		LD A,AAH
	12		LD (DE),A
	3E 55		LD A,55H		write byte 55 to 6AAAH
	32 AA 6A	LD (6AAAH),A
	3E A0		LD A,A0H		write byte A0 to 7555H
4E1EH	12		LD (DE),A

IMPLEMENT OPTION BYTE/PAGE LOAD HERE
4E1FH	11 03 60	LD DE,6003H		DE = color table address in EEPROM
4E22H	3E 07       LD A,CLR1	 	A = color1 = white
	12 		LD (DE),A		change CLR1 in EEPROM table
	1C		INC E			point DE to next color address in EEPROM
	3E 00		LD A,CLR2		A = color2 = black
	12		LD (DE),A		change CLR2 in EEPROM table
	
	FB		EI
4E2AH	C9		RET 			your done, go home

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

End of Using EEPROMs Document
Revision 1.0
MCM Design
Nov 2019